<template>
  <div class="box">
    <h1>这是A组件,{{ count }}</h1>
    <el-button type="primary" @click="handlePlus">+</el-button>
    <el-button type="success" size="default" @click="handleAddStu">
      新增学员
    </el-button>

    <div v-for="item in stu">姓名:{{ item.name }} 成绩:{{ item.score }}</div>
  </div>
</template>

<script>
export default {
  computed: {
    count() {
      return this.$store.state.count.num;
    },
    stu() {
      return this.$store.state.student.stu;
    },
  },
  methods: {
    handlePlus() {
      this.$store.commit("plus", 10); //触发模块化后的mutations
      // this.$store.commit("count/plus", 10); //触发模块化后的mutations
    },
    handleAddStu() {
      //触发mutation
      // this.$store.commit("addStuMut", {
      //   name: "张某",
      //   score: Math.round(Math.random() * 40 + 40),
      // });

      //触发action
      this.$store.dispatch("addStuAction", {
        name: "张某",
        score: Math.round(Math.random() * 40 + 40),
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  width: 50%;
  height: 500px;
  border: 1px solid #333;
}
</style>
